package com.jd.cms.service.impl;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jd.cms.mapper.ContentCategoryMapper;
import com.jd.cms.pojo.ContentCategory;
import com.jd.cms.service.ContentCategoryService;


@Service("contentCategoryService")
public class ContentCategoryServiceImpl implements ContentCategoryService {
	@Autowired
	private ContentCategoryMapper contentCategoryMapper ;
	@Override
	public List<ContentCategory> getContentCategory(Long parentId)
			throws Exception {
		return contentCategoryMapper.getContentCategory(parentId);
	}
	
	@Override
	public int tx_addContentCategory(ContentCategory ccat) throws Exception {
		ccat.setCreated(new Date());
		ccat.setUpdated(new Date());
		ccat.setIsParent(false);
		int result = contentCategoryMapper.addContentCategory(ccat);
		ContentCategory parent = contentCategoryMapper.getContentCategoryById(ccat.getParentId());
		if(!parent.getIsParent()){
			parent.setIsParent(true);
			return contentCategoryMapper.updateContentCategory(parent);
		}
		return result;
	}

}
